package com.sanpang.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sanpang.common.pojo.EasyUIDataGridResult;
import com.sanpang.mapper.TbItemMapper;
import com.sanpang.pojo.TbItem;
import com.sanpang.pojo.TbItemExample;
import com.sanpang.pojo.TbItemExample.Criteria;
import com.sanpang.pojo.TbItemExample.Criterion;
import com.sanpang.service.ItemService;

/**
 * 
 * 
 * @author sanpang
 *
 */
@Service
public class ItemServiceImpl implements ItemService {
	
	@Autowired
	private TbItemMapper tbItemMapper;

	@Override
	public TbItem getItemById(long iteamId) {
		//根据主键查询
		TbItem item =tbItemMapper.selectByPrimaryKey(iteamId);
		
		//也可以根据逆向工程生成的设置条件查询
		TbItemExample example = new TbItemExample();
		Criteria    criterion = example.createCriteria();
		criterion.andIdEqualTo(iteamId);
		//执行查询
		List<TbItem> list =tbItemMapper.selectByExample(example);
		if(list!=null && list.size()>0)
		return list.get(0);
		
		return null;
		
	}

	@Override
	public EasyUIDataGridResult getIteamList(int page, int rows) {
		//设置分页信息
		PageHelper.startPage(1, 10);
		//查询
		TbItemExample example =new TbItemExample(); 
		List<TbItem>  list    =tbItemMapper.selectByExample(example);
		//取分页结果
		EasyUIDataGridResult result = new EasyUIDataGridResult();
		//所有的数据
		result.setRows(list);
		PageInfo<TbItem> pageInfo = new PageInfo<TbItem>(list);
		//总  
		result.setTotal(pageInfo.getTotal());
		return result;
	}

}
